package com.aounhui.customer.controller;

import com.aounhui.common.entity.Result;
import com.aounhui.common.exceptions.OrderException;
import com.aounhui.common.exceptions.SellCommodityException;
import com.aounhui.customer.entity.Order;
import com.aounhui.customer.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author aounhui
 * @version 1.0
 * @date 2021/6/16 16:49
 */
@RestController
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping(value = "/customer/order/buy")
    public Result buy(@RequestBody Order order,@RequestHeader("token") String token) {
        try {
            order.setUserId(token);
            //订单订购时间
            order.setOderTime(new Date());
            return orderService.buy(order);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("订单失败，{}", e.toString());
            return Result.error("订单异常");
        }

    }
}
